package cn.ming.leo.service;

import java.util.List;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.SqlRow;

import cn.ming.leo.bean.DoorTools;

@Component
public class ScheduledTasks {

	@Scheduled(fixedRate = 60000)
	public void reportCurrentTime() {
		String sql = "select id from door_tools where status = 1 and timestampdiff(HOUR,create_time,now()) >= 4;";

		List<SqlRow> sqlRows = Ebean.createSqlQuery(sql).findList();

		for (SqlRow sqlRow : sqlRows) {
			String id = sqlRow.getString("id");
//			Tools tools = Tools.find.byId(id);
//			tools.setToolsStatus(0);
//			tools.update();
//
//			String sql1 = "select id from door_tools where tools_id = " + id + " order by create_time desc limit 1";
//			SqlRow row = Ebean.createSqlQuery(sql1).findUnique();
//			
			DoorTools doorTools = DoorTools.find.byId(id);
			doorTools.setStatus(6);
			doorTools.update();

		}
	}

}